<html>
<head>
<title>Calculator</title>
</head>
<body>
<h1>Calculator</h1>
<h2>Prasanth Veerina & Samir Mody</h2>

<form action="calculator.php" method="get">
Expression: <input type="text" name="fexp"/>
<input type="submit"/>
</form>

<?php
function e($errno, $errstr, $errfile, $errline) {
	print "Invalid expression\n";
}
set_error_handler('e');

$exp = $_GET["fexp"];
if ($exp) {
	print "<h3> Result: </h3>";
	$exp = preg_replace('/\s/',"",$exp);

	$match = preg_match('/^[0-9\+\-\/\*\.]+$/', $exp);
	$match2 = preg_match('/[\+\-\/\*][\+\/\*]/', $exp);
	$match2 += preg_match('/\.[0-9]*\./', $exp);
	$match2 += preg_match('/\-\-/', $exp);

	//$match2 += preg_match('/\/0+[^1-9]/', $exp);
	//$match2 += preg_match('/\/0+\.0*[^1-9]/', $exp);

	if ($match2 > 0 ) {
		print "Invalid Expression!";
	} else if ($match > 0 ){
		eval("\$result = $exp;");
		print "$exp = $result";
	} else {
		print "Invalid Expression!";
	}
}
?>

</body>
</html>